package cn.learn.service.cargo.impl;

import cn.learn.dao.cargo.ProductDao;
import cn.learn.domain.cargo.Product;
import cn.learn.domain.cargo.ProductExample;
import cn.learn.service.cargo.ProductService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductDao productDao;

    @Override
    public Product findById(String id) {
        Product product = productDao.selectByPrimaryKey(id);
        return product;
    }

    @Override
    public void save(Product product) {
        product.setId(UUID.randomUUID().toString().replace("-", ""));
        product.setCreateTime(new Date());
        productDao.insert(product);
    }

    @Override
    public void update(Product product) {
        product.setCreateTime(new Date());
        productDao.updateByPrimaryKey(product);
    }

    @Override
    public void delete(String id) {
        productDao.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo findAll(ProductExample product, int page, int size) {
        PageHelper.startPage(page, size);
        List<Product> products = productDao.selectByExample(product);
        PageInfo pageInfo = new PageInfo(products);
        return pageInfo;
    }

    @Override
    public void updateByResult(ProductExample productResult) {

    }

    @Override
    public List<Map> findqian() {
        List<Map> mapList = productDao.findqian();
        return mapList;
    }

}
